<%@ Application Language="C#" %>

<script RunAt="server">

    //string lang = "en-US";
    string mNetLib;
    string mBanco;
    
    void Application_BeginRequest(Object sender, EventArgs e)
    {
        //System.Threading.Thread.CurrentThread.CurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo(lang);
        //System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(lang);
        /*Response.Cache.SetNoStore();
        Response.Cache.SetNoServerCaching();
        Response.Cache.SetAllowResponseInBrowserHistory(false);
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.CacheControl = "no-cache";
        Response.AppendHeader("Pragma", "no-cache");
        Response.Expires = 0;*/
        GC.Collect(0);
        GC.SuppressFinalize(this);
    }
    
    void Application_Start(object sender, EventArgs e)
    {
        AppVars.sageXrtApp = Application; 
    }

    void Application_End(object sender, EventArgs e)
    {

    }
    void Application_Error(object sender, EventArgs e)
    {
        HttpContext ctx = HttpContext.Current;
        string msg = "";
        try
        {

            Exception exception = ctx.Server.GetLastError();

            string errorInfo =
               "<style> body {font-family:'Verdana';font-weight:normal;font-size: .7em;color:black;} p {font-family:'Verdana';font-weight:normal;font-size: .7em;color:black;margin-top: 0px} b {font-family:'Verdana';font-weight:bold;margin-top: -5px} H1 { font-family:'Verdana';font-weight:normal;font-size:18pt;color:red } H2 { font-family:'Verdana';font-weight:normal;font-size: .7em;color:black } pre {font-family:'Lucida Console';font-size: .9em}         .marker {font-weight: bold; color: black;text-decoration: none;}.version {color: gray;}.error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } </style>" +
               "<body bgcolor='white'><span><H1>Universe Erro.<hr width=100% size=1 color=silver></H1>" +
               "<br/><p><input id='btnVoltar' type='button' value='" + GlobalTranslate.translateTermo(((univNETLib)Session[modzGeneral.mUsu_codigo + "NetLib"]).ExtIdioma, "Voltar") + "' onclick='javascript:window.open(" + '"' + "../../Default.aspx" + '"' + ", " + '"' + "_top" + '"' + "," + '"' + '"' + "," + '"' + "true" + '"' + ")'/>" +
               "<input id='btnLogin1' type='button' value='" + GlobalTranslate.translateTermo(((univNETLib)Session[modzGeneral.mUsu_codigo + "NetLib"]).ExtIdioma, "Logoff") + "' onclick='javascript:window.open(" + '"' + "../../Login.aspx?client=-1" + '"' + ", " + '"' + "_top" + '"' + "," + '"' + '"' + "," + '"' + "true" + '"' + ")'/></p>" +
               "<input id='btnLogin' type='button' value='" + GlobalTranslate.translateTermo(((univNETLib)Session[modzGeneral.mUsu_codigo + "NetLib"]).ExtIdioma, "Sair") + "' onclick='javascript:window.open(" + '"' + "../../Finalize/Halt.aspx?client=-1" + '"' + ", " + '"' + "_top" + '"' + "," + '"' + '"' + "," + '"' + "true" + '"' + ")'/></p>" +
               "<font face='Arial, Helvetica, Geneva, SunSans-Regular, sans-serif '>" +
               "<br><font color=black size=2px><b>URL: </b></font>" + ctx.Request.Url.ToString() +
               "<br/><br/><table width=100% bgcolor='#ffffcc'><tr><td><font color=black size=2px><b>Error:</b><br/></font><font color=red><b><i>" + exception.InnerException.Message.Replace("\r\n", "<br/>") + "<i></b></font></tr></td></table>";

            msg = exception.InnerException.Message;
                    
            if (exception.InnerException.InnerException != null)
            {
                errorInfo += "<table width=100% bgcolor='#ffffcc'><tr><td><font color=black size=2px><br/></font><font color=red><b><p>" + exception.InnerException.InnerException.ToString().Replace("\r\n", "<br/>") + "<p></b></font></tr></td></table>";
                msg += exception.InnerException.InnerException.ToString();                
            }

            try
            {
                errorInfo += "<br/><table width=100% bgcolor='#ffffcc'><tr><td><font color=black size=2px><b>Source:</b><br/><p>" + exception.InnerException.Source.Replace("\r\n", "<br/>") + "</p></font></tr></td></table>" +
                "<br/><table width=100% bgcolor='#ffffcc'><tr><td><font color=black size=2px><b>Stack trace:</b><br/><p>" + exception.InnerException.StackTrace.Replace("\r\n", "<br/>") + "</p></font></tr></td></table>" +
                "<body/>";
                msg += exception.InnerException.Source;
                msg += exception.InnerException.StackTrace;
            }
            catch { }

            ctx.Response.Write(errorInfo);

            ctx.Server.ClearError();

            Context.ClearError();
            ctx.ClearError();

            /*try
            {
                if (DBConnection.GetConnection() == null || (DBConnection.GetConnection().State != System.Data.ConnectionState.Open))
                {
                    if (DBConnection.GetConnection() == null)
                        msg = "Invalid Operation. The connection is closed .";
                    else if (DBConnection.GetConnection().State != System.Data.ConnectionState.Open)
                        msg = "Invalid Operation. The connection is closed.";
                    else
                        msg = msg.Substring(0, Math.Min(620,msg.Length-1)).Replace("\r\n", "</br>");
                    
                    ctx.Response.Redirect("../../LogoutUniverse.aspx?msg=" + msg);
                    Session.Abandon();
                }
            }
            catch { }*/
        }
        catch { }
        
    }

    void Session_Start(object sender, EventArgs e)
    {

        mNetLib = modzGeneral.mUsu_codigo + "NetLib";
        mBanco = modzGeneral.mUsu_codigo + "Banco";
        
        univNETLib NetLib = new univNETLib();
        univBanco Banco = new univBanco();
        
        Session[mNetLib] = NetLib;
        Session[mBanco] = Banco;
    }

    void Session_End(object sender, EventArgs e)
    {
        DBConnection.CloseConnection();
    }
       
</script>

